package Operation;

import Book.Book;
import Book.BookList;
import User.User;

import java.util.Scanner;

public class AddOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("新增图书");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入新增书的书名：");
        String name = scanner.nextLine();
        System.out.println("请输入这本书的作者：");
        String author = scanner.nextLine();
        System.out.println("请输入这本书的价格：");
        int price = scanner.nextInt();
        scanner.nextLine();
        System.out.println("请输入这本书的类型：");
        String type = scanner.nextLine();

        Book book = new Book(name,author,price,type);

        //判断书架上是否有这本书：
        int CurrentSide = bookList.getUseSide();
        for (int i = 0; i < CurrentSide; i++) {
            Book book1 = bookList.getBooks(i);
            if (book1.getName().equals(name)) {
                System.out.println("对不起，您的书架上已经有了这本书！");
                return;
            }
        }
        //把新增的图书放在数组的最后一个位置
        bookList.setBooks(CurrentSide,book);
        bookList.setUseSide(CurrentSide+1);
    }
}
